package com.service.loan.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.client.common.config.IdWorker;
import com.client.model.pojo.loan.AiruiRecord;
import com.client.model.pojo.user.ArUser;
import com.client.model.vo.common.Result;
import com.client.model.vo.common.ResultCodeEnum;
import com.client.model.vo.creditLoanVo.LoanVo;
import com.client.model.vo.userVo.ArUserVo;
import com.service.loan.feignService.UserFeignCreditCardService;
import com.service.loan.service.AiruiRecordService;
import com.service.loan.mapper.AiruiRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author liuwenju
* @description 针对表【airui_record】的数据库操作Service实现
* @createDate 2024-04-01 20:58:48
*/
@Slf4j
@Service
public class AiruiRecordServiceImpl extends ServiceImpl<AiruiRecordMapper, AiruiRecord>
    implements AiruiRecordService{
    @Autowired
    private UserFeignCreditCardService userFeignCreditCardService;
    @Autowired
    private AiruiRecordMapper airuiRecordMapper;
    @Override
    public Result<String> loan(LoanVo loanVo,String token) {
        log.info("loanVo--------------->{}",loanVo);
        log.info("token--------------->{}",token);
        ArUserVo arUserVo = new ArUserVo();
        arUserVo.setIden(loanVo.getIden());
        arUserVo.setToken(token);
        arUserVo.setCode(loanVo.getCode());
        arUserVo.setRealName(loanVo.getRealName());
        arUserVo.setMobile(loanVo.getMobile());
        log.info("arUser------->{}",arUserVo);
        Result<String> result = this.userFeignCreditCardService.theUserIsExist(arUserVo);
        if (result.getCode()!=200){
            return Result.build("用户已存在", ResultCodeEnum.IDEN_LESS);
        }
        AiruiRecord airuiRecord = new AiruiRecord();
        airuiRecord.setMobile(loanVo.getMobile());
        airuiRecord.setIden(loanVo.getIden());
        airuiRecord.setAddress(loanVo.getAddress());
        airuiRecord.setUname(loanVo.getRealName());
        airuiRecord.setCardNum(loanVo.getCardNum());
        IdWorker idWorker = new IdWorker();
        airuiRecord.setId(idWorker.nextId());
        int insert = this.airuiRecordMapper.insert(airuiRecord);
        if (insert==1) {
            return Result.build("申请成功", ResultCodeEnum.SUCCESS);
        }else {
            return Result.build("申请失败", ResultCodeEnum.SYSTEM_ERROR);
        }
    }
}




